<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课堂随机点名系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(120deg, #1e90ff, #00bfff, #87cefa);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            position: relative;
            overflow-x: hidden;
        }
        
        /* 卡通装饰元素 */
        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: 
                radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.2) 25px, transparent 26px),
                radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.2) 15px, transparent 16px),
                radial-gradient(circle at 40% 80%, rgba(255, 255, 255, 0.2) 30px, transparent 31px),
                radial-gradient(circle at 90% 90%, rgba(255, 255, 255, 0.2) 20px, transparent 21px);
            z-index: -1;
        }
        
        .container {
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            width: 90%;
            max-width: 800px;
            padding: 30px;
            text-align: center;
            position: relative;
            overflow: hidden;
        }
        
        .container::before {
            content: "";
            position: absolute;
            top: -10px;
            left: -10px;
            right: -10px;
            bottom: -10px;
            border: 2px dashed #1e90ff;
            border-radius: 25px;
            opacity: 0.3;
            pointer-events: none;
        }
        
        h1 {
            color: #1e90ff;
            font-size: 2.5rem;
            margin-bottom: 20px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            position: relative;
            display: inline-block;
        }
        
        h1::after {
            content: "";
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 100px;
            height: 4px;
            background: linear-gradient(to right, #1e90ff, #00bfff);
            border-radius: 2px;
        }
        
        .name-display {
            background: linear-gradient(135deg, #f0f8ff, #e6f2ff);
            border-radius: 15px;
            padding: 40px 20px;
            margin: 25px 0;
            min-height: 200px;
            display: flex;
            justify-content: center;
            align-items: center;
            box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1);
            border: 2px solid #b3d9ff;
            position: relative;
            overflow: hidden;
        }
        
        .name-display::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 10px;
            background: linear-gradient(to right, #1e90ff, #00bfff, #1e90ff);
            border-radius: 5px 5px 0 0;
        }
        
        #current-name {
            font-size: 3.5rem;
            color: #0066cc;
            font-weight: bold;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .selected {
            color: #ff5500 !important;
            font-size: 4rem !important;
            text-shadow: 0 0 15px rgba(255, 85, 0, 0.5) !important;
        }
        
        .controls {
            display: flex;
            flex-direction: column;
            gap: 20px;
            margin-top: 20px;
        }
        
        .buttons {
            display: flex;
            gap: 15px;
            justify-content: center;
            flex-wrap: wrap;
        }
        
        button {
            background: linear-gradient(to right, #1e90ff, #00bfff);
            color: white;
            border: none;
            padding: 12px 25px;
            font-size: 1.1rem;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        button:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
        }
        
        button:active {
            transform: translateY(1px);
        }
        
        #edit-btn {
            background: linear-gradient(to right, #ff8c00, #ff5500);
        }
        
        .speed-control {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
            margin-top: 10px;
        }
        
        .speed-control label {
            color: #0066cc;
            font-weight: bold;
        }
        
        #speed-slider {
            width: 80%;
            height: 10px;
            -webkit-appearance: none;
            appearance: none;
            background: linear-gradient(to right, #ccddff, #0066cc);
            outline: none;
            border-radius: 10px;
        }
        
        #speed-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            background: #1e90ff;
            cursor: pointer;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        }
        
        .edit-panel {
            background: linear-gradient(135deg, #f9f9f9, #e6f2ff);
            border-radius: 15px;
            padding: 20px;
            margin-top: 25px;
            border: 2px dashed #b3d9ff;
            display: none;
        }
        
        .edit-panel h2 {
            color: #1e90ff;
            margin-bottom: 15px;
            font-size: 1.5rem;
        }
        
        .name-list {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            justify-content: center;
            margin-bottom: 20px;
            max-height: 200px;
            overflow-y: auto;
            padding: 10px;
        }
        
        .name-item {
            background: linear-gradient(135deg, #e6f2ff, #cce5ff);
            padding: 8px 15px;
            border-radius: 50px;
            display: flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        
        .name-item span {
            color: #0066cc;
        }
        
        .name-item button {
            background: #ff5500;
            padding: 4px 8px;
            font-size: 0.8rem;
            border-radius: 50%;
            width: 25px;
            height: 25px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .add-name {
            display: flex;
            gap: 10px;
            justify-content: center;
            margin-top: 15px;
        }
        
        #new-name {
            padding: 10px 15px;
            border: 2px solid #b3d9ff;
            border-radius: 50px;
            font-size: 1rem;
            width: 200px;
            outline: none;
        }
        
        #add-btn {
            padding: 10px 20px;
        }
        
        .hint {
            margin-top: 20px;
            color: #6699cc;
            font-size: 0.9rem;
        }
        
        @keyframes gradientBG {
            0% {
                background-position: 0% 50%;
            }
            50% {
                background-position: 100% 50%;
            }
            100% {
                background-position: 0% 50%;
            }
        }
        
        @media (max-width: 768px) {
            h1 {
                font-size: 2rem;
            }
            
            #current-name {
                font-size: 2.5rem;
            }
            
            .selected {
                font-size: 3rem !important;
            }
            
            .buttons {
                flex-direction: column;
                align-items: center;
            }
            
            button {
                width: 100%;
                max-width: 250px;
                justify-content: center;
            }
            
            .add-name {
                flex-direction: column;
                align-items: center;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>课堂随机点名</h1>
        
        <div class="name-display">
            <span id="current-name">准备开始</span>
        </div>
        
        <div class="controls">
            <div class="buttons">
                <button id="toggle-btn">
                    <i class="fas fa-play"></i> 开始
                </button>
                <button id="edit-btn">
                    <i class="fas fa-edit"></i> 编辑名单
                </button>
            </div>
            
            <div class="speed-control">
                <label for="speed-slider">滚动速度调节</label>
                <input type="range" id="speed-slider" min="1" max="10" value="5">
            </div>
        </div>
        
        <div class="edit-panel" id="edit-panel">
            <h2><i class="fas fa-users"></i> 学生名单管理</h2>
            
            <div class="name-list" id="name-list">
                <!-- 姓名列表将通过JavaScript动态生成 -->
            </div>
            
            <div class="add-name">
                <input type="text" id="new-name" placeholder="输入新姓名">
                <button id="add-btn">
                    <i class="fas fa-plus"></i> 添加
                </button>
            </div>
        </div>
        
        <p class="hint">点击"开始"按钮开始随机点名，再次点击停止并选中学生</p>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 初始学生名单
            let nameList = [
                "任洪韬", "林宜岑", "刘柬鸿", "王隽桐", "乔志润", 
                "奉嘉凯", "王飞阳", "李思凝", "邱战", "何家辉", 
                "马轩", "倪阳", "李子涵", "兰昕", "曹高高", 
                "阮开珩", "李晨嘉", "杨景名", "岳子煜", "赵翎云", 
                "刘铭杰", "肖杨梦秋", "李建宝", "倪飞扬", "付俊凯", 
                "杨家瑞", "薛锐", "郑园馨", "刘闻熙", "郑祖彦杰"
            ];
            
            const toggleBtn = document.getElementById('toggle-btn');
            const editBtn = document.getElementById('edit-btn');
            const currentName = document.getElementById('current-name');
            const speedSlider = document.getElementById('speed-slider');
            const editPanel = document.getElementById('edit-panel');
            const nameListContainer = document.getElementById('name-list');
            const newNameInput = document.getElementById('new-name');
            const addBtn = document.getElementById('add-btn');
            
            let isRolling = false;
            let rollInterval;
            let rollSpeed = 100; // 初始速度值（毫秒）
            
            // 初始化页面
            renderNameList();
            
            // 渲染姓名列表
            function renderNameList() {
                nameListContainer.innerHTML = '';
                nameList.forEach((name, index) => {
                    const nameItem = document.createElement('div');
                    nameItem.className = 'name-item';
                    nameItem.innerHTML = `
                        <span>${name}</span>
                        <button class="delete-btn" data-index="${index}">
                            <i class="fas fa-times"></i>
                        </button>
                    `;
                    nameListContainer.appendChild(nameItem);
                });
                
                // 添加删除事件监听
                document.querySelectorAll('.delete-btn').forEach(btn => {
                    btn.addEventListener('click', function() {
                        const index = parseInt(this.getAttribute('data-index'));
                        deleteName(index);
                    });
                });
            }
            
            // 删除姓名
            function deleteName(index) {
                nameList.splice(index, 1);
                renderNameList();
                saveToLocalStorage();
            }
            
            // 添加新姓名
            addBtn.addEventListener('click', function() {
                const newName = newNameInput.value.trim();
                if (newName && !nameList.includes(newName)) {
                    nameList.push(newName);
                    renderNameList();
                    newNameInput.value = '';
                    saveToLocalStorage();
                } else if (nameList.includes(newName)) {
                    alert('该姓名已存在！');
                }
            });
            
            // 按Enter键添加姓名
            newNameInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    addBtn.click();
                }
            });
            
            // 更新滚动速度
            function updateSpeed() {
                // 将滑块值（1-10）转换为速度值（300ms - 50ms）
                // 滑块值越大，速度越快（间隔时间越短）
                rollSpeed = 300 - (speedSlider.value * 25);
                
                if (isRolling) {
                    clearInterval(rollInterval);
                    startRolling();
                }
            }
            
            // 开始滚动名字
            function startRolling() {
                rollInterval = setInterval(() => {
                    const randomIndex = Math.floor(Math.random() * nameList.length);
                    currentName.textContent = nameList[randomIndex];
                    currentName.classList.remove('selected');
                }, rollSpeed);
            }
            
            // 停止滚动并选中当前名字
            function stopRolling() {
                clearInterval(rollInterval);
                currentName.classList.add('selected');
            }
            
            // 按钮点击事件
            toggleBtn.addEventListener('click', function() {
                if (isRolling) {
                    stopRolling();
                    toggleBtn.innerHTML = '<i class="fas fa-play"></i> 开始';
                } else {
                    if (nameList.length === 0) {
                        alert('请先添加学生姓名！');
                        editBtn.click();
                        return;
                    }
                    startRolling();
                    toggleBtn.innerHTML = '<i class="fas fa-stop"></i> 停止';
                }
                isRolling = !isRolling;
            });
            
            // 编辑按钮点击事件
            editBtn.addEventListener('click', function() {
                if (editPanel.style.display === 'block') {
                    editPanel.style.display = 'none';
                    editBtn.innerHTML = '<i class="fas fa-edit"></i> 编辑名单';
                } else {
                    editPanel.style.display = 'block';
                    editBtn.innerHTML = '<i class="fas fa-times"></i> 关闭编辑';
                }
            });
            
            // 滑块事件
            speedSlider.addEventListener('input', updateSpeed);
            
            // 初始化速度
            updateSpeed();
            
            // 保存到本地存储
            function saveToLocalStorage() {
                localStorage.setItem('nameList', JSON.stringify(nameList));
            }
            
            // 从本地存储加载
            function loadFromLocalStorage() {
                const savedList = localStorage.getItem('nameList');
                if (savedList) {
                    nameList = JSON.parse(savedList);
                    renderNameList();
                }
            }
            
            // 页面加载时尝试从本地存储加载数据
            loadFromLocalStorage();
        });
    </script>
</body>
</html>